package com.black.pay.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

public class JSONHandlerExecption implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView modelAndView = new ModelAndView();
        MappingJackson2JsonView view =new MappingJackson2JsonView();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code",500);
        map.put("msg", "系统异常");
        view.setAttributesMap(map);
        modelAndView.setView(view);
        ex.printStackTrace();
        return modelAndView;
    }
}
